package IOStream.ConvertStream;

import java.io.*;
import java.nio.charset.Charset;

/**
 * ClassName:Dome004
 * Package:IOStream.ConvertStream
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/3/3-19:11
 * @Version:v1.0
 */
public class Dome004 {
    /*将本地文件中的GBK文件,转成UTF-8*/
    public static void main(String[] args) throws IOException {
        //JDK11以前的方案
//        InputStreamReader isr = new InputStreamReader(new FileInputStream("E:\\aaa\\b.txt"), "GBK");
//        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("E:\\aaa\\c.txt"), "UTF-8");
//        int b;
//        while ((b = isr.read()) != -1) {
//            osw.write(b);
//        }
//        osw.close();
//        isr.close();

        FileReader fr = new FileReader("E:\\aaa\\b.txt", Charset.forName("GBK"));
        FileWriter fw = new FileWriter("E:\\aaa\\c.txt", Charset.forName("UTF-8"));
        int b;
        while ((b = fr.read()) != -1) {
            fw.write(b);
        }
        fw.close();
        fr.close();
    }
}
